package flc.ast.utils;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import flc.ast.bean.MyDebugBean;
import flc.ast.bean.MyPassKindBean;
import flc.ast.bean.MyUdpCombBean;


public class AppSpUtils {
    private static final String SP_NAME = "appCollSp";
    private static final SPUtils sSpUtils = SPUtils.getInstance(SP_NAME);

    public static void savePasswordList(List<MyPassKindBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_password_list, json);
    }

    public static List<MyPassKindBean> getPasswordList() {
        String json = sSpUtils.getString(Key.key_password_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyPassKindBean>>() {
        }.getType());
    }

    public static void saveTcpServerList(List<MyDebugBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_tcp_server_list, json);
    }

    public static List<MyDebugBean> getTcpServerList() {
        String json = sSpUtils.getString(Key.key_tcp_server_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyDebugBean>>() {
        }.getType());
    }

    public static void saveTcpClientList(List<MyDebugBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_tcp_client_list, json);
    }

    public static List<MyDebugBean> getTcpClientList() {
        String json = sSpUtils.getString(Key.key_tcp_client_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyDebugBean>>() {
        }.getType());
    }

    public static void saveUdpServerList(List<MyDebugBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_udp_server_list, json);
    }

    public static List<MyDebugBean> getUdpServerList() {
        String json = sSpUtils.getString(Key.key_udp_server_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyDebugBean>>() {
        }.getType());
    }

    public static void saveUdpClientList(List<MyDebugBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_udp_client_list, json);
    }

    public static List<MyDebugBean> getUdpClientList() {
        String json = sSpUtils.getString(Key.key_udp_client_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyDebugBean>>() {
        }.getType());
    }

    public static void saveUdpCombList(List<MyUdpCombBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_udp_comb_list, json);
    }

    public static List<MyUdpCombBean> getUdpCombList() {
        String json = sSpUtils.getString(Key.key_udp_comb_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyUdpCombBean>>() {
        }.getType());
    }

    interface Key {
        String key_password_list = "key_password_list";
        String key_tcp_server_list = "key_tcp_server_list";
        String key_tcp_client_list = "key_tcp_client_list";
        String key_udp_server_list = "key_udp_server_list";
        String key_udp_client_list = "key_udp_client_list";
        String key_udp_comb_list = "key_udp_comb_list";
    }
}